package myJs.api

import myJs.Implicits._
import myJs.myPkg.MyFetch
import org.scalajs.macrotaskexecutor.MacrotaskExecutor.Implicits._
import shared.Pojo._
import shared.tsPojo.TsPojo
import upickle.default._

/**
 * Created by yz on 7/5/2022
 */
object BrowseGene {

  import TsPojo.browseGene._

  val baseUrl = s"${Api.apiUrl}/gepLiver/browseGene"

  def hTissueBoxplotImage(request: HTissueBoxplotImage.Request) = {
    val url = s"${baseUrl}/hTissueBoxplotImage"
    MyFetch.postRnText(url = s"${url}", data = write(request), headers = Map("Content-Type" -> "application/json")).map { str =>
      read[HTissueBoxplotImage.Response](str)
    }
  }

  def mTissueBoxplotImage(request: MTissueBoxplotImage.Request) = {
    val url = s"${baseUrl}/mTissueBoxplotImage"
    MyFetch.postRnText(url = s"${url}", data = write(request), headers = Map("Content-Type" -> "application/json")).
      map { str =>
        read[MTissueBoxplotImage.Response](str)
      }
  }

  def boxplotData(request: BoxplotData.Request) = {
    val url = s"${baseUrl}/boxplotData"
    MyFetch.postRnText(url = s"${url}", data = write(request), headers = Map("Content-Type" -> "application/json")).
      map { str =>
        read[BoxplotData.Response](str)
      }
  }

  def geneExp(request: GeneExp.Request) = {
    val url = s"${baseUrl}/geneExp"
    MyFetch.postRnText(url = s"${url}", data = write(request), headers = Map("Content-Type" -> "application/json")).
      map { str =>
        read[List[ujson.Obj]](str)
      }
  }

  def barData(phenotype: String) = {
    val url = s"${baseUrl}/barData"
    MyFetch.get(url = s"${url}?phenotype=${phenotype}").map { any =>
      any.toJArJDJAn
    }
  }

  def cellType(phenotype: String) = {
    val url = s"${baseUrl}/cellType"
    MyFetch.getRnStr(url = s"${url}?phenotype=${phenotype}").map { str =>
      read[List[ujson.Obj]](str)
    }
  }

  def cellLineImage(request: CellLineImage.Request) = {
    val url = s"${baseUrl}/cellLineImage"
    MyFetch.postRnText(url = s"${url}", data = write(request), headers = Map("Content-Type" -> "application/json")).
      map { str =>
        read[CellLineImage.Response](str)
      }
  }


}
